#! /bin/sh

CWD=`cd $(dirname $0);pwd;`
HOSTFILE="$CWD/hosts.txt"

if [ $# -ge 2 ]; then
  id="$1"
  cmds="$2"
elif [ $# -ge 1 ];then
  id="$1"
else
  echo "go server_id [\"cmds\"]"
  exit
fi

line=`grep "^$id:" $HOSTFILE`

if [[ $line =~ "^([^:]*):([^:]*):([^:]*):([^:]*):([^:]*)$" ]]; then
  user=${BASH_REMATCH[2]}
  pass=${BASH_REMATCH[3]}
  host=${BASH_REMATCH[4]}
  port=${BASH_REMATCH[5]}
fi

exec ${CWD}/go.exp $user $pass $host $port "$cmds"
